package com.cn.lyl.thread;

public class Customer extends  Thread {
    @Override
    public void run() {
        while (true){
            synchronized (WareHouse.obj){
                if(WareHouse.count ==0){
                    System.out.println("消费者退出");
                    return;
                }
                if(!WareHouse.isNull){
                    WareHouse.count--;
                    System.out.println("消费者者"+getName()+"消费,目标剩余"+WareHouse.count+"件");
                    WareHouse.isNull=true;
                    WareHouse.obj.notifyAll();
                }
                try {
                    WareHouse.obj.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
